package com.shut.vehicle.pojo;

import com.alibaba.fastjson2.JSONArray;
import com.shut.vehicle.exception.ServiceException;
import io.netty.util.internal.StringUtil;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author 卢斌
 */
@Getter
@Setter
@NoArgsConstructor
public class Device implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer id;
    private String name;
    private String model;
    private String location;
    private Integer imageNum;
    private JSONArray demoImage;


    public static void checkDeviceParam(Device device) {
        if (device == null) {
            throw new ServiceException("无效的设备信息");
        }
        if (StringUtil.isNullOrEmpty(device.getName())) {
            throw new ServiceException("缺少设备名称");
        }
        if (device.getName().length() > 200) {
            throw new ServiceException("设备名称超长");
        }
        if (StringUtil.isNullOrEmpty(device.getModel())) {
            throw new ServiceException("请指定设备型号");
        }
        if (device.getModel().length() > 50) {
            throw new ServiceException("设备型号超长");
        }
        if (StringUtil.isNullOrEmpty(device.getLocation())) {
            throw new ServiceException("请指定设备位置名称");
        }
        if (device.getLocation().length() > 200) {
            throw new ServiceException("设备地址信息超长");
        }
    }

}
